<template>
    <div class="list" ref="wrapper">
      <div>
        <HomeHeader></HomeHeader>
        <HomeSwiper :list="swiperList"></HomeSwiper>
        <HomeIcons :list="iconList"></HomeIcons>
        <HomeHotList :list="hotList"></HomeHotList>
        <HomeReacommend :list="recommendList"></HomeReacommend>
        <HomeWeekend :list="weekendList"></HomeWeekend>
      </div>
    </div>
</template>
<script>
import BScroll from 'better-scroll'
import axios from 'axios'
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeHotList from './components/HotList'
import HomeReacommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
export default {
  name: 'home',
  data () {
    return {
      lastCity: '',
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
      hotList: []
    }
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.wrapper)
    this.lastCity = this.$store.state.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.$store.state.city) {
      this.lastCity = this.$store.state.city
      this.getHomeInfo()
    }
  },
  methods: {
    getHomeInfo () {
      axios.get('api/index.json?city=' + this.$store.state.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        this.swiperList = res.data.swiperList
        this.iconList = res.data.iconList
        this.recommendList = res.data.recommendList
        this.weekendList = res.data.weekendList
        this.hotList = res.data.HotList
      }
    }
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeHotList,
    HomeReacommend,
    HomeWeekend
  }
}
</script>
<style lang="stylus" scoped>
  .list
    position absolute
    top 0
    right 0
    left 0
    bottom 0
</style>
